package some.black.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import some.black.dao.BlackDao;
import some.black.domain.BlockMemberCommand;
import some.member.dao.MemberDao;

@Controller
public class BlockMemberController {
	
	@Autowired
	private BlackDao blackDao;
	

	@Autowired
	private MemberDao memberDao;
	@RequestMapping("blockMember.do")
	public ModelAndView form(@RequestParam("block_id") String block_id,
							 @RequestParam("blockDay") String blockDay,
							 @RequestParam("blockCount") int blockCount){
		
		int check = blackDao.checkBlockMember(block_id);
		String result;
		if(check==0){
			BlockMemberCommand blockMember = new BlockMemberCommand();
			blockMember.setId(block_id);
			blockMember.setBlock_date(blockDay);
			blockMember.setBlockCount(blockCount);
			blackDao.insertBlockMember(blockMember);
			blackDao.setBlockGrade(block_id);
			result = "success";
		}else if(check==1){
			result = "already";
		}else
			result = "failure";
			
		ModelAndView mav = new ModelAndView();
		mav.setViewName("blockResult");
		mav.addObject("result", result);
		
		return mav;
	}
	
	
}
